package variabilitysmelldetection.measurement.measures.component;

import java.util.List;

import variabilitysmelldetection.measurement.measures.Measure;
import variabilitysmelldetection.measurement.models.ComponentItem;
import variabilitysmelldetection.measurement.models.MethodItem;



public class NumberOfOperationOverrides extends Measure {

	public NumberOfOperationOverrides() {
		super("Number of Operation Overrides", "NOOr");
	}

	public void measure(List<ComponentItem> items){
		int numOfOverrides = 0;
		List<MethodItem> methods = null;
		for (ComponentItem classe : items) {

			methods = classe.getMethods();

			for (MethodItem method : methods) {
				numOfOverrides = 0;

				if (!method.isRefinement() && !classe.isRefinement()) {

					for (ComponentItem c : items) {
						
						if (c.isRefinement() || c.getSuperClass().equals(classe.getName())) {
							
							for (MethodItem m : c.getMethods()) {
								if (!m.isRefinement()) {
									if (!c.getParentName().equals(classe.getParentName()) &&
										m.getName().equals(method.getName()) &&
										c.getName().equals(classe.getName())) {
										numOfOverrides++;
									}
								}
							}
						}
					}
				}
				NumberOfOperationOverrides nooo = new NumberOfOperationOverrides();
				nooo.setValue(numOfOverrides);
				method.addMeasure(nooo);
			}
		}
	}
}
